package utils

import (
	"github.com/Chain-Zhang/pinyin"
	"strings"
)

// GetPinyin 将汉字转换为拼音
func GetPinyin(chain string) (quanPin, jianPin string) {
	var err error
	if quanPin, err = pinyin.New(chain).Split("").Mode(pinyin.InitialsInCapitals).Convert(); err == nil {
		for i := 0; i < len(quanPin); i++ {
			// 获取字母的ASCII码，是否为大写A~Z(65~90)，如果是则取出来
			if 64 < quanPin[i] && quanPin[i] < 91 {
				jianPin += string(quanPin[i])
			}
		}
		quanPin = strings.ToLower(quanPin)
		jianPin = strings.ToLower(jianPin)
		return quanPin, jianPin
	}
	return "", ""
}
